#include <deque>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int N,P,K,limit;
deque<int> dq;
int dist[1010];
struct edge
{
	int to;
	int cost;
};
vector<edge> G[10002];
bool check(int cost);
void bfs(void);
int main()
{
	edge temp_edge;
	cin>>N>>P>>K;
	for(int i=0; i<P; i++)
	{
		int from,to,cost;

		cin>>from>>to>>cost;
		temp_edge.to=to;
		temp_edge.cost=cost;
		G[from].push_back(temp_edge);
		temp_edge.to=from;
		G[to].push_back(temp_edge);
	}
	int left=0,right=10000002;
	
	while(left<right-1)
	{
		int mid=(left+right)/2;
		//cout<<left<<","<<mid<<","<<right<<endl;
		if(check(mid))	right=mid;
		else			left=mid;
	}
	if(right==10000002)		cout<<-1<<endl;
	else 					cout<<right<<endl;
	return 0;
}
bool check(int num)
{
	fill(dist+1,dist+1+N,1000001);
	dq.clear();
	dist[1]=0;
	limit=num;
	dq.push_front(1);
	bfs();
	//cout<<dist[N]<<endl;
	if(dist[N]>K)	return false;
	else			return true;
}
void bfs(void)
{

	while(!dq.empty())
	{
		int V=dq.front();
		dq.pop_front();
		//cout<<"->"<<V<<endl;
		for(int i=0; i<G[V].size(); i++)
		{
			if(dist[G[V][i].to]>dist[V]+(G[V][i].cost>limit))
			{
				dist[G[V][i].to]=dist[V]+(G[V][i].cost>limit);
				if(G[V][i].cost>limit)		dq.push_front(G[V][i].to);
				else						dq.push_back(G[V][i].to);
			}
		}

	}
}